package com.os.china.task;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduledTasks {

	@Autowired
	private SimpMessagingTemplate messagingTemplate;

	private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

	@Scheduled(cron = "*/2 * * * * *")
	public void reportCurrentTime() {
		// 向用户发送消息
		messagingTemplate.convertAndSendToUser("admin", "/point/notifications",
				"现在时间：" + dateFormat.format(new Date()));
	}

}